#!/bin/bash
################### 备份日志脚本 ################
# 执行之前：
# 	1. 去除特殊字符：sed -i 's/\r//' backup_log.sh
# 	2. 添加执行权限：chmod +x backup_log.sh
# 执行命令：./backup_log.sh
# 执行之后：
# 脚本说明：
#########################################################

# shellcheck disable=SC2006
DATE=`date -d 'yesterday' +%Y-%m-%d`
echo "backup log begin $DATE"
# shellcheck disable=SC2164
LOG_PATH=/home/logs
# shellcheck disable=SC2164
cd $LOG_PATH
mkdir baklog/"$DATE"
echo "mkdir success: baklog/$DATE"

# shellcheck disable=SC2044
for i in `find . -maxdepth 1 -type f -name '*.log'`
do
   echo "backup log: $i"
   cp "$i" ./baklog/"$DATE"/"$i"
   echo '' > "$i"
done
echo "backup log success $DATE"